package com.yyj.controller;

import com.github.pagehelper.PageInfo;
import com.yyj.entity.*;
import com.yyj.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/*跨域*/
@CrossOrigin
@RestController
@RequestMapping("/Pet")
public class PetController {
    @Autowired
    PetService petService;

    @GetMapping("/search")
    public Result getBySearch(Params params) {
        PageInfo<Pet> info = petService.getBySearch(params);
        return Result.success(info);
    }

    //用户添加动物
    @PostMapping
    public Result insertPet(@RequestBody Pet pet) {
        if (pet.getPetId() == null) {
            //添加
            petService.insertPet(pet);
            return Result.success();
        } else {
            //修改
            petService.updatePet(pet);
            return Result.success();
        }
    }

    @DeleteMapping("/{petId}")
    public Result deletePet(@PathVariable Integer petId) {
        petService.delete(petId);
        return Result.success();
    }
}
